package yawning.mew.gui.characters.attributes;

import javax.swing.JPanel;
import javax.swing.JTextPane;

import yawning.mew.gui.tools.CharacterDataSource;

import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;

@SuppressWarnings("serial")
public class GeneralAttributes extends JPanel {
	private CharacterDataSource source; 
	private JSpinner spnStrength;
	private JSpinner spnAgility;
	private JSpinner spnStamina;
	private JSpinner spnIntellect;
	private JSpinner spnSpirit;
	private JSpinner spnMastery;

	public GeneralAttributes(CharacterDataSource source) {
		this.source = source;
		setLayout(null);
		spnStrength = new JSpinner();
		spnStrength.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnStrength.setBounds(104, 13, 84, 20);
		add(spnStrength);
		
		JTextPane txtpnStrenght = new JTextPane();
		txtpnStrenght.setEditable(false);
		txtpnStrenght.setText("Strength:");
		txtpnStrenght.setBounds(10, 11, 84, 22);
		add(txtpnStrenght);
		
		JTextPane txtpnAgility = new JTextPane();
		txtpnAgility.setEditable(false);
		txtpnAgility.setText("Agility:");
		txtpnAgility.setBounds(10, 44, 84, 22);
		add(txtpnAgility);
		
		spnAgility = new JSpinner();
		spnAgility.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnAgility.setBounds(104, 44, 84, 20);
		add(spnAgility);
		
		JTextPane txtpnStamina = new JTextPane();
		txtpnStamina.setEditable(false);
		txtpnStamina.setText("Stamina:");
		txtpnStamina.setBounds(10, 77, 84, 22);
		add(txtpnStamina);
		
		spnStamina = new JSpinner();
		spnStamina.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnStamina.setBounds(104, 77, 84, 20);
		add(spnStamina);
		
		spnIntellect = new JSpinner();
		spnIntellect.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnIntellect.setBounds(104, 110, 84, 20);
		add(spnIntellect);
		
		JTextPane txtpnIntellect = new JTextPane();
		txtpnIntellect.setEditable(false);
		txtpnIntellect.setText("Intellect:");
		txtpnIntellect.setBounds(10, 110, 84, 22);
		add(txtpnIntellect);
		
		spnSpirit = new JSpinner();
		spnSpirit.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnSpirit.setBounds(104, 143, 84, 20);
		add(spnSpirit);
		
		JTextPane txtpnSpirit = new JTextPane();
		txtpnSpirit.setEditable(false);
		txtpnSpirit.setText("Spirit:");
		txtpnSpirit.setBounds(10, 143, 84, 22);
		add(txtpnSpirit);
		
		JTextPane txtpnMastery = new JTextPane();
		txtpnMastery.setEditable(false);
		txtpnMastery.setText("Mastery");
		txtpnMastery.setBounds(10, 175, 84, 22);
		add(txtpnMastery);
		
		spnMastery = new JSpinner();
		spnMastery.setModel(new SpinnerNumberModel(new Integer(0), new Integer(0), null, new Integer(1)));
		spnMastery.setToolTipText("Mastery rating");
		spnMastery.setBounds(104, 175, 84, 20);
		add(spnMastery);
		initDataBindings();
	}

	
	protected void initDataBindings() {
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty = BeanProperty.create("toon.ability_Strength");
		BeanProperty<JSpinner, Object> jSpinnerBeanProperty = BeanProperty.create("value");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty, spnStrength, jSpinnerBeanProperty, "aStr");
		autoBinding.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_1 = BeanProperty.create("toon.ability_Agility");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_1, spnAgility, jSpinnerBeanProperty, "aAgi");
		autoBinding_1.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_2 = BeanProperty.create("toon.ability_Stamina");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_2 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_2, spnStamina, jSpinnerBeanProperty, "aStam");
		autoBinding_2.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_3 = BeanProperty.create("toon.ability_Intellect");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_3 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_3, spnIntellect, jSpinnerBeanProperty, "aIntel");
		autoBinding_3.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_4 = BeanProperty.create("toon.ability_Spirit");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_4 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_4, spnSpirit, jSpinnerBeanProperty, "aSprt");
		autoBinding_4.bind();
		//
		BeanProperty<CharacterDataSource, Integer> characterDataSourceBeanProperty_5 = BeanProperty.create("toon.rating_Mastery");
		AutoBinding<CharacterDataSource, Integer, JSpinner, Object> autoBinding_5 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, source, characterDataSourceBeanProperty_5, spnMastery, jSpinnerBeanProperty, "ratingMastery");
		autoBinding_5.bind();
	}
}
